import 'package:flutter/material.dart';
import 'package:node_chat/Model/ChatModel.dart';
import 'package:node_chat/pages/CameraPage.dart';
import 'package:node_chat/pages/StatusPage.dart';

import '../pages/ChatPage.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen(
      {super.key, required this.chatmodels, required this.sourchat});

  final List<ChatModel> chatmodels;
  final ChatModel sourchat;

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen>
    with SingleTickerProviderStateMixin {
  late TabController _controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = TabController(length: 4, vsync: this, initialIndex: 1);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Whatsapp Clone"),
        actions: [
          IconButton(icon: const Icon(Icons.search), onPressed: () {}),
          PopupMenuButton<String>(
            onSelected: (value) {
              print(value);
            },
            itemBuilder: (BuildContext conttext) {
              return [
                const PopupMenuItem(
                  value: "new group",
                  child: Text("new group"),
                ),
                const PopupMenuItem(
                  value: "新群组",
                  child: Text("新群组"),
                ),
                const PopupMenuItem(
                  value: "whatsapp",
                  child: Text("whatsapp web"),
                ),
                const PopupMenuItem(
                  value: "发消息",
                  child: Text("发消息"),
                ),
                const PopupMenuItem(
                  value: "设置",
                  child: Text("设置"),
                ),
              ];
            },
          )
        ],
        bottom: TabBar(
          controller: _controller,
          indicatorColor: Colors.white,
          tabs: const [
            Tab(
              icon: Icon(Icons.camera_alt),
            ),
            Tab(
              text: "CHATS",
            ),
            Tab(
              text: "STATUS",
            ),
            Tab(
              text: "CAALS",
            ),
          ],
        ),
      ),
      body: TabBarView(
        controller: _controller,
        children: [
          const CameraPage(),
          ChatPage(
            chatmodels: widget.chatmodels,
            sourchat: widget.sourchat,
          ),
          const StatusPage(),
          const Text("calss"),
        ],
      ),
    );
  }
}
